package Test;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class Client {
    private Socket socket;
    public static void main(String[] args) {
        Client client = new Client();
        client.start();
    }
    public Client(){
        try {
            System.out.println("正在连接服务端");
            socket = new Socket("127.0.0.1",8088);
            System.out.println("与服务端建立连接成功");
        } catch (IOException e) {
            System.out.println("Socket建立失败");
            e.printStackTrace();
        }
    }
    public void start(){
        try {
            OutputStream out = socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(out, StandardCharsets.UTF_8);
            BufferedWriter bw = new BufferedWriter(osw);
            PrintWriter pw = new PrintWriter(bw,true);
            Scanner s = new Scanner(System.in);
            System.out.print("请输入用户名：");
            String name = s.nextLine();
            System.out.print("请输入密码：");
            String pwd = s.nextLine();
            pw.println(name);
            pw.println(pwd);
            InputStream in = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(in, StandardCharsets.UTF_8);
            BufferedReader br = new BufferedReader(isr);
            System.out.println(br.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
